home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_087 / elib / elib.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  129 lines

  1. /* elib.c -- an exec library compiled with Aztec 3.30b, small model        */
  2.  
  3. /* created by jim mackraz using mylib.asm by neil katin
  4.  * may be used and distributed providing this comment block
  5.  * is retained in the source code
  6.  */
  7.  
  8. #include "elib.h"
  9.  
  10. extern  PFL        libfunctab[];    /* my function table (libface.asm)        */
  11. extern    LONG    funkyInit();    /* hacked up version of Aztec crt0.a68    */
  12.  
  13. LONG    myExpunge();
  14.  
  15. struct InitTable myInitTab =  {
  16.     sizeof (struct MyBase),
  17.     libfunctab,
  18.     NULL,                    /* will initialize my data in funkymain()    */
  19.     funkyInit
  20. };
  21.  
  22. #define MYREVISION    0        /* would be nice to auto-increment this        */
  23.  
  24. char myname[] = "mylib.library";
  25. char myid[] = "mylib 1.0 (23 Oct 1986)\r\n";
  26.  
  27. extern struct Resident    myRomTag;
  28.  
  29. /*
  30.  * this function is my C-language library initRoutine.  It is called
  31.  * by funkyInit() after register saves and small model initialization is
  32.  * done.
  33.  */
  34.  
  35. LONG
  36. funkymain(libbase, seglist)
  37. struct    MyBase    *libbase;
  38. ULONG            seglist;
  39. {
  40.     register    struct MyBase *base;
  41.  
  42.     /* cookie    */
  43.     base = libbase;
  44.     base->mb_Cookie = 0xDEAD1234;    /* debug kind of stuff                */
  45.     base->mb_SegList = seglist;
  46.  
  47.     /* init. library structure (since I don't do automatic data init.)    */
  48.     base->mb_Lib.lib_Node.ln_Type = NT_LIBRARY;
  49.     base->mb_Lib.lib_Node.ln_Name = (char *) myname;    
  50.     base->mb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  51.     base->mb_Lib.lib_Version = myRomTag.rt_Version;
  52.     base->mb_Lib.lib_Revision = MYREVISION;
  53.     base->mb_Lib.lib_IdString = (APTR) myid;
  54.  
  55.     /* ----- do your own initialization here -----    */
  56. }
  57.  
  58. LONG
  59. myOpen(base)    /* baseptr in A6, version in D0 */
  60. struct    MyBase *base;
  61. {
  62.     /* mark us as having another customer                    */
  63.     base->mb_Lib.lib_OpenCnt++;
  64.  
  65.     /* prevent delayed expunges (standard procedure)        */
  66.     base->mb_Lib.lib_Flags &= ~LIBF_DELEXP;
  67.  
  68.     return ((LONG) base);
  69. }
  70.  
  71. LONG
  72. myClose(base)
  73. struct    MyBase *base;
  74. {
  75.     LONG    retval = 0;
  76.  
  77.     if ((--base->mb_Lib.lib_OpenCnt == 0) &&
  78.             (base->mb_Lib.lib_Flags & LIBF_DELEXP))
  79.     {
  80.         /* no more people have me open,
  81.          * and I have a delayed expunge pending
  82.          */
  83.         retval = myExpunge(); /* return segment list    */
  84.     }
  85.  
  86.     return (retval);
  87. }
  88.  
  89. LONG
  90. myExpunge(base)
  91. struct    MyBase    *base;
  92. {
  93.     ULONG            seglist = 0;
  94.     LONG            libsize;
  95.  
  96.     if (base->mb_Lib.lib_OpenCnt == 0)
  97.     {
  98.         /* really expunge: remove libbase and freemem    */
  99.  
  100.         seglist    = base->mb_SegList;
  101.  
  102.         Remove(base);
  103.  
  104.         libsize = base->mb_Lib.lib_NegSize + base->mb_Lib.lib_PosSize;
  105.         FreeMem((char *) base - base->mb_Lib.lib_NegSize, (LONG) libsize);
  106.     }
  107.     else
  108.     {
  109.         base->mb_Lib.lib_Flags &= LIBF_DELEXP;
  110.     }
  111.  
  112.  
  113.     /* return NULL or real seglist                */
  114.     return ((LONG) seglist);
  115. }
  116.  
  117. LONG
  118. GetDown()
  119. {
  120.     return (77);
  121. }
  122.  
  123. ULONG
  124. Double(arg)
  125. ULONG arg;
  126. {
  127.     return (2 * arg);
  128. }
  129.